fix(github): number unsafe findings and count the same unit on every surface - #1152
Conversation
edf7c7c to
f63363a
Compare
a9464f4 to
299ca30
Compare
f63363a to
479f901
Compare
299ca30 to
4d7f088
Compare
479f901 to
f9ffbf2
Compare
4d7f088 to
b7bd46d
Compare
f9ffbf2 to
99647b1
Compare
d470d98 to
85e0eca
Compare
85e0eca to
cf1978d
Compare
There was a problem hiding this comment.
Pull request overview
Updates SchemaBot’s unsafe-change rendering so both GitHub PR comments and the CLI present a flat, numbered list (one line per finding) and ensure any displayed counts match the number of rendered findings.
Changes:
- Render unsafe findings as a single ordered list (one numbered line per finding) in PR comments and CLI output.
- Make “unsafe change(s) detected” counts consistently reflect the number of rendered findings (not the number of change objects).
- Update template previews and tests to assert against the new numbered output format.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| TEMPLATES.md | Updates documentation/examples to show numbered unsafe findings and consistent counts. |
| pkg/webhook/templates/plan.go | Switches unsafe warning rendering to a flat numbered list and counts findings. |
| pkg/webhook/templates/apply_commands.go | Uses the shared numbered unsafe-finding rendering for blocked apply comments. |
| pkg/webhook/plan_test.go | Updates webhook template tests to assert numbered unsafe findings. |
| pkg/cmd/internal/templates/plan.go | Updates CLI output to count and print unsafe findings as a numbered list. |
| pkg/cmd/internal/templates/plan_unsafe_test.go | Updates CLI template tests to assert the new numbered output. |
Suppressed comments (1)
pkg/webhook/templates/plan.go:1088
*n++is not valid Go syntax on a pointer dereference. This will fail to compile; increment the dereferenced value with(*n)++(or*n += 1).
for _, r := range reasons {
*n++
fmt.Fprintf(sb, "%d. %s: %s\n", *n, table, ui.CodeQuoteIdentifiers(r))
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
…surface The unsafe-changes headings advertise a count, but the list below was unordered and, on the CLI, counted changes while the PR comment counted findings — the same apply could say 3 in the terminal and 4 on the PR. Both surfaces now render one numbered line per finding (the table name repeats instead of nesting a sub-list), and every heading counts findings, so the count always equals the number of lines below it and a finding can be referenced by its number. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
cf1978d to
f5c24ed
Compare
morgo
left a comment
There was a problem hiding this comment.
🤖 Approved on Morgan's behalf by his AI agent.
Presentation layer only, 37/37 green.
The claim I went after was "count the same unit on every surface" — a fix that corrects one counted heading and leaves a sibling behind is the classic way this goes wrong. writeUnsafeChangesList has three callers, and only WriteUnsafeChangesBlocked was changed. Checked the other two at f5c24ed9: WriteUnsafeChangesWarning heads with "Unsafe Changes Detected:" and WriteUnsafeWarningAllowed with "The following unsafe changes will be applied:" — neither prints a count, so there's no invariant for the now-per-finding list to break. The title holds.
Two things I liked that the description doesn't mention:
- It quietly removes an in-place mutation. The old
writeUnsafeChangeItemdidreasons[i] = ui.CodeQuoteIdentifiers(r)on the sliceui.LintReasonsreturned. That's fine only as long asLintReasonsalways hands back a freshly-allocated slice; the moment it caches or returns a sub-slice of something shared, the old code corrupts it for the next caller. Applying the quoting inline at format time makes that class of bug unreachable. - Threading
*intthroughwriteUnsafeChangeItemkeeps numbering continuous across tables, which is the whole point — per-table restarts would have made "2 is the blocker" ambiguous.
Nits, none blocking:
countUnsafeFindingsnow exists in bothpkg/cmd/internal/templatesandpkg/webhook/templateswith the same semantics. Two packages, so sharing costs a dependency — probably right to duplicate, just worth a comment on one pointing at the other so they don't drift, since the count/list invariant depends on them agreeing.- The zero-reason fallback still differs by surface: CLI renders
table: ChangeType, the PR comment renders a baretablewith no explanation at all. Pre-existing, not introduced here, but the comment side is the one an operator reads under pressure.
The PR comment's zero-reason fallback rendered a bare table name while the CLI rendered the engine's change type; thread ChangeType through the webhook unsafe-change data so both surfaces explain the finding. Cross-reference the two countUnsafeFindings helpers so they don't drift. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
|
🤖 Both nits addressed in a516271:
Reply by Claude (Fable 5). |
Renders unsafe changes as a flat numbered list — one line per finding — on both the PR comment and the CLI, and makes every heading count the same unit the list shows.
3. `audit_log`: drop), falling back to the bare table name only when neither is available.PR comment — before / after
Before:
After:
CLI — before / after (note the count now matches the list)
Before:
After:
This PR was written by an AI agent (Claude Code, model Claude Fable 5) on behalf of the author.